<template>
  <div class="app-container" v-loading="loading">
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="券基本信息" name="1">
        <BasicInfo
          :tab="1"
          @push="push"
          @radioStyle="radioStyle"
          :activeId="activeId"
          ref="BasicInfo"
        ></BasicInfo>
      </el-tab-pane>
      <el-tab-pane label="配置关联项目" name="2" v-if="radioCheck==1">
        <relation :tab="2" @push="push" :activeId="activeId" :code2="code2" ref="relation"></relation>
      </el-tab-pane>
      <el-tab-pane label="关联医院" name="3" v-if="radioCheck==1">
        <relation :tab="3" @push="push" :activeId="activeId" :code23="code3" ref="relation1"></relation>
      </el-tab-pane>
      <el-tab-pane label="配置场景" name="4" v-if="radioCheck==2">
        <ConfigureCoupons
          :tab="4"
          @push="push"
          :activeId="activeId"
          :code4="code4"
          ref="ConfigureCoupons"
        ></ConfigureCoupons>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { hospitalDropDown } from "@/api/doctorManage";

import {
  butlerListDropdown,
  listDoctorsDropdown,
  findAllProjectListOfHospital,
  saveComment
} from "@/api/itemEvaluate";
import BasicInfo from "./ticketAssembly/BasicInfo.vue";
import relation from "./ticketAssembly/relation.vue";
import ConfigureCoupons from "./ticketAssembly/ConfigureCoupons.vue";
export default {
  name: "AddPlatformCard",
  components: { BasicInfo, relation, ConfigureCoupons },
  data() {
    return {
      activeName: "1",
      radioCheck: null,
      loading: false,
      params: {},
      code2: "",
      code3: "",
      code4: "",
      activeId: this.$route.query.id ? this.$route.query.id : null
    };
  },
  mounted() {
    this.userId = this.$route.query.id - 0;
    this.type = this.$route.query.type;
    if (this.type == "edit") {
      this.$route.meta.title = "编辑平台券";
    } else {
      this.$route.meta.title = "添加平台券";
    }
  },
  methods: {
    // 没有填写基础信息时返回基础信息提示消息
    showMsg() {
      this.$message({
        showClose: true,
        message: "请先填写基本信息",
        type: "warning"
      });
      this.activeName = "1";
    },
    // 4个tab页面都提交成功后返回列表
    handleBack() {
      if (this.radioCheck == 1 && this.activeId && this.code2 && this.code3) {
        this.$router.push("/platformCard");
      } else if (this.radioCheck == 2 && this.activeId) {
        this.$router.push("/platformCard");
      }
    },
    // 配置信息
    radioStyle(radio) {
      let Radio = radio;
      this.radioCheck = Radio;
      console.log("radio", radio);
    },

    push(tab, id, radio, only) {
      // this.activeName = tab + 1 + "";
      console.log("id", id);

      this.activeId = id;

      if (tab == 1) {
        if (this.radioCheck == 1) {
          this.activeName = tab + 1 + "";

          console.log(this.$refs["relation1"]);
          this.$refs["relation1"].prodfn(id);
        } else {
          this.activeName = tab + 3 + "";
        }

        // this.$refs["relation1"].hostlist(id);
      } else if (tab == 2) {
        if (id) {
          this.$refs["relation1"].hostlist();
          this.activeName = tab + 1 + "";
          this.code2 = only;
          this.handleBack();
        } else {
          this.showMsg();
        }
      } else if (tab == 3) {
        if (id) {
          this.activeName = tab + 1 + "";
          this.code3 = only;
          this.handleBack();
        } else {
          this.showMsg();
        }
      } else if (tab == 4) {
        if (id) {
          // this.activeName = tab;
          this.code4 = only;
          this.handleBack();
        } else {
          this.showMsg();
        }
      }
    },
    handleClick(tab, event) {
      console.log(this.activeName);
    }
  }
};
</script>
<style scoped>
.app-container {
  padding: 0.1px !important;
}
.el-textarea__inner {
  display: block;
  width: 300px !important;
  min-height: 50px !important;
  box-sizing: border-box;
}
</style>
